﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Sunlit.House.Configuration;
using Sunlit.House.Web;

namespace Sunlit.House.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class HouseDbContextFactory : IDesignTimeDbContextFactory<HouseDbContext>
    {
        public HouseDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<HouseDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            HouseDbContextConfigurer.Configure(builder, configuration.GetConnectionString(HouseConsts.ConnectionStringName));

            return new HouseDbContext(builder.Options);
        }
    }
}
